package com.hotec.PROJECT_NAME.modules.sys.service;

import cn.hutool.core.collection.CollectionUtil;
import com.hotec.PROJECT_NAME.component.basic.BaseService;
import com.hotec.PROJECT_NAME.modules.sys.entity.SysMessageRead;
import com.hotec.PROJECT_NAME.modules.sys.mapper.SysMessageReadMapper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;

;import java.util.Date;
import java.util.List;

/**
 * @author llb
 * @date
 */
@Service
public class SysMessageReadService extends BaseService<SysMessageRead, SysMessageReadMapper> {

    public Date queryNewReadTime(String targetId) {
        Example example = Example.builder(SysMessageRead.class)
                .select("createTime")
                .andWhere(
                        Sqls.custom()
                                .andEqualTo("accountId", getCurrentAccountId(true))
                                .andEqualTo("targetId", targetId)
                )
                .orderByDesc("createTime")
                .build();

        List<SysMessageRead> sysMessageReads = mapper.selectByExample(example);

        if(CollectionUtil.isEmpty(sysMessageReads)) return null;

        return sysMessageReads.get(0).getCreateTime();
    }
}
